<template>
  <view>
    <view class="page">
      <view class="block_4">
        <view class="box_3">
          <!-- <view class="accomplishFile"></view> -->

          <file :pdfImage='pdfImage' W='568rpx' H='1120rpx' @swiperChange='swiperChange'></file>

          <movable-area class="area" scale-area v-show="url">
            <movable-view class='move-big' direction="all" inertia out-of-bounds damping="10" friction="0" scale
              @change="onChange">
              <view class="area_name">
                <image class="area_image" :src="url" mode="aspectFit"></image>
              </view>
            </movable-view>
          </movable-area>

          <view class="text-wrapper_1">
            <text lines="1" class="text_2">{{pageNo}}/{{pdfImage.length}}</text>

          </view>
          <text lines="1" class="text_3" v-if="!url">展示合同内容</text>
        </view>
        <view class="text-wrapper_2">
          <image src="../../static/++.png" class="text_4" @click="sign_3()"></image>
        </view>
        <view class="box_4">
          <view class="group_2"></view>
          <view lines="1" decode="true" class="text_5">
            <navigator url="/subpkg/signature/signature?is=1" class="signature">签字</navigator>
            <text class="confirm" @click="toHome()">确认签署</text>
          </view>
        </view>
      </view>
    </view>

    <view class="zzc" v-show="orLayer"></view>
    <view class="T_box_2" v-show="orLayer">
      <view class="T_text-wrapper_5">
        <text lines="1" class="T_text_1" @click="orLayer=!orLayer">×</text>
        <text lines="1" class="T_text_2">拍证</text>
        <text lines="1" class="T_text_3" @click="upfile()">完成</text>
      </view>
      <text lines="1" class="T_paragraph_1">为了使文件更具有法律效应，可上传:单据、房本、签署现场、卸货过程等信息，文件<br />大小不能超过30MB。</text>
      <image src="../../static/JZ.png" class="T_image_1" v-if="!src"></image>
      <image :src="src" class="T_image_2" v-else></image>
      <view class="T_group_4">
        <view class="T_text-wrapper_3">
          <text lines="1" class="T_text_5" @click="addVideo()">添加视频</text>
        </view>
        <view class="T_text-wrapper_4">
          <text lines="1" class="T_text_6" @click="addVideo()">添加图片</text>
        </view>
      </view>
      <view class="T_group_3"></view>
      <view class="T_text-wrapper_2" @click="removeImage()">
        <text lines="1" class="T_text_4">×</text>
      </view>
    </view>

  </view>
</template>

<script>
  import file from '../../components/file/file.vue'
  export default {
    components: {
      file
    },
    data() {
      return {
        pageNo: 1, //页数
        orLayer: 'false',
        //存储视频或者图片
        src: '',
        fileInfo: null,
        res: null,
        url: '', //签名路径
        param:{//带给服务器的参数
          contractId: null,
          pageNumber:null,
          signX:null,
          signY:null,
          signImgBase:null
        }
      }
    },
    onLoad(e) {
      this.orLayer = !this.orLayer
      this.url = e.url
    },
    mounted() {
      const value = uni.getStorageSync("file");
      // console.log(value)
      if (value) {
        this.fileInfo = value
      }
      this.getPDFImage()
    },
    methods: {
      swiperChange(e) {
        this.pageNo = e.pagNo+1
        console.log(e.pagNo+1)
      },
      onChange(e) {
        this.param.signX=e.detail.x + 108/2*5
        this.param.signY=(100-(e.detail.y)/2/560)*5
      },
      //访问服务器pdf切图返回
      getPDFImage() {
        let param = {
          fileId: this.fileInfo.fileInfo.fileId
        }
        this.$store.dispatch('contract/getPDFImage', param)
      },
      async toHome() {
        //整理参数
        this.param.contractId=this.fileInfo.id//合同id
        this.param.pageNumber=this.pageNo//页数
        this.param.signImgBase=this.url//bare64签名
        try{
          await this.$store.dispatch('contract/upSignature', this.param)
          let title='添加成功!'
          uni.$showMsg(title)
          uni.reLaunch({
            url: '/pages/home/home'
          })
        }catch(e){
          let title=e.message
          uni.$showMsg(title)
        }
        
      },
      sign_3() {
        this.orLayer = !this.orLayer
      },
      //添加视频或图片
      addVideo() {
        uni.chooseMedia({
          count: 1,
          mediaType: ['image', 'video'],
          sourceType: ['album', 'camera'],
          maxDuration: 30,
          camera: 'back',
          success: (res) => {
            console.log(res)
            this.src = res.tempFiles[0].tempFilePath
            this.res = res
          }
        })
      },
      //清空照片或视频
      removeImage() {
        this.src = ''
      },
      upfile() {
        const token = uni.getStorageSync("token")
        let value = this.src.split('.')[1]
        //整理参数

        uni.uploadFile({
          url: 'http://47.100.78.124:9981/file/contract-evidence-info/uploadFile', //仅为示例，非真实的接口地址
          filePath: this.res.tempFiles[0].tempFilePath,
          name: 'file',
          formData: {
            contractId: this.fileInfo.id,
            fileType: value == 'png' ? 1 : 2,
            uploadType: 2
          },
          header: {
            ContentType: 'multipart/form-data',
            Authorization: token.accessToken,
            // Authorization: 'Bearer P5Czad8SgYT9jTJQtgYunKfl30JrDRrvpUU9tNNJBpcruFuvLyvqGNa9UbfptJx3pArOC7qkhZLT6npmjXpxM3Ys4IodgL9L1Fg6cllW6BqutVkRoUf0PZyPaY6hrW9i'
          },
          success: (uploadFileRes) => {
            let title = '上传成功!'
            uni.$showMsg(title)
            this.orLayer = !this.orLayer
          },
          fai: (e) => {
            let title = '上传失败!'
            uni.$showMsg(title)
          }
        });
      }

    },
    computed: {
      pdfImage() {
        let PDFImages = this.$store.state.contract.pdfImage
        return PDFImages || []
      }

    }


  }
</script>

<style>
  .area_image {
    width: 100%;
    height: 100%;
    /* 图片旋转90% */
    -moz-transform: rotate(-90deg);
    -webkit-transform: rotate(-90deg);
  }

  .area {
    width: 430rpx;
    height: 1050rpx;
    /* background: lightpink; */
  }

  .move-big {
    position: relative;
    top: 80%;
    left: 50%;
  }

  .area_name {
    background-color: rgba(255, 255, 255, 0.680000);
    width: 150rpx;
    height: 80rpx;
    border: 2px dashed rgba(29, 29, 29, 0.68);
    display: flex;
    flex-direction: column;
  }



  .accomplishFile {

    position: absolute;
  }

  .signature {
    position: absolute;
  }

  .confirm {
    position: absolute;
    right: 0;
  }

  .T_box_2 {
    background-color: rgba(255, 255, 255, 1.000000);
    border-radius: NaNrpx;
    position: relative;
    width: 750rpx;
    /* height: 1012rpx; */
    height: 1196rpx;
    margin-top: -1334rpx;
    display: flex;
    flex-direction: column;
    border-radius: 35rpx 35rpx 0 0;
    top: 140rpx;
  }

  .T_text-wrapper_5 {
    width: 678rpx;
    height: 32rpx;
    flex-direction: row;
    display: flex;
    margin: 44rpx 0 0 30rpx;
  }

  .T_text_1 {
    width: 30rpx;
    height: 31rpx;
    webkit-text-stroke: 1px rgba(102, 102, 102, 1);
    overflow-wrap: break-word;
    color: rgba(102, 102, 102, 1);
    font-size: 48rpx;
    font-family: SimHei;
    text-align: left;
    white-space: nowrap;
    line-height: 24rpx;
  }

  .T_text_2 {
    width: 60rpx;
    height: 28rpx;
    overflow-wrap: break-word;
    color: rgba(159, 137, 89, 1.000000);
    font-size: 30rpx;
    font-family: SimHei;
    text-align: left;
    white-space: nowrap;
    line-height: 24rpx;
    margin: 3rpx 0 0 286rpx;
  }

  .T_text_3 {
    width: 60rpx;
    height: 29rpx;
    overflow-wrap: break-word;
    color: rgba(159, 137, 89, 1.000000);
    font-size: 30rpx;
    font-family: SimHei;
    text-align: left;
    white-space: nowrap;
    line-height: 24rpx;
    margin: 3rpx 0 0 242rpx;
  }

  .T_paragraph_1 {
    width: 670rpx;
    height: 42rpx;
    overflow-wrap: break-word;
    color: rgba(247, 86, 60, 1);
    font-size: 18rpx;
    font-family: Adobe Heiti Std R;
    text-align: left;
    line-height: 24rpx;
    margin: 45rpx 0 0 30rpx;
  }

  .T_image_1 {
    width: 198rpx;
    height: 221rpx;
    margin: 134rpx 0 0 81rpx;
  }

  .T_image_2 {
    width: 300rpx;
    height: 346rpx;
    margin: 75rpx 0 0 35rpx;
  }

  .T_group_4 {
    width: 575rpx;
    height: 82rpx;
    flex-direction: row;
    display: flex;
    justify-content: space-between;
    /* margin: 357rpx 0 55rpx 85rpx; */
    position: absolute;
    bottom: 55rpx;
    left: 85rpx;
  }

  .T_text-wrapper_3 {
    background-color: rgba(171, 151, 102, 1.000000);
    border-radius: 10rpx;
    height: 82rpx;
    display: flex;
    flex-direction: column;
    width: 254rpx;
  }

  .T_text_5 {
    width: 123rpx;
    height: 29rpx;
    overflow-wrap: break-word;
    color: rgba(255, 255, 255, 1);
    font-size: 30rpx;
    font-family: SimHei;
    text-align: left;
    white-space: nowrap;
    line-height: 24rpx;
    margin: 27rpx 0 0 66rpx;
  }

  .T_text-wrapper_4 {
    background-color: rgba(171, 151, 102, 1.000000);
    border-radius: 10rpx;
    height: 82rpx;
    display: flex;
    flex-direction: column;
    width: 254rpx;
  }

  .T_text_6 {
    width: 121rpx;
    height: 29rpx;
    overflow-wrap: break-word;
    color: rgba(255, 255, 255, 1);
    font-size: 30rpx;
    font-family: SimHei;
    text-align: left;
    white-space: nowrap;
    line-height: 24rpx;
    margin: 27rpx 0 0 74rpx;
  }

  .T_group_3 {
    position: absolute;
    left: 29rpx;
    top: 230rpx;
    width: 300rpx;
    height: 346rpx;
    border: 4px solid rgba(204, 204, 204, 1);
    display: flex;
    flex-direction: column;
  }

  .T_text-wrapper_2 {
    background-color: rgba(204, 204, 204, 1.000000);
    border-radius: 50%;
    height: 40rpx;
    display: flex;
    flex-direction: column;
    width: 40rpx;
    position: absolute;
    left: 320rpx;
    top: 213rpx;
  }

  .T_text_4 {
    width: 16rpx;
    height: 16rpx;
    webkit-text-stroke: 1px rgba(255, 255, 255, 1);
    overflow-wrap: break-word;
    color: rgba(255, 255, 255, 1.000000);
    font-size: 24rpx;
    font-family: SimHei;
    text-align: left;
    white-space: nowrap;
    line-height: 24rpx;
    margin-top: 9rpx;
    margin-left: 12rpx;
  }
</style>

<style>
  .zzc {
    position: absolute;
    height: 100%;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    background-color: rgba(0, 0, 0, 0.5);

  }

  .page {
    background-color: rgba(255, 255, 255, 1.000000);

    position: relative;
    width: 750rpx;
    height: 1475rpx;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }

  .block_1 {
    height: 144rpx;
    background: url(https://lanhu.oss-cn-beijing.aliyuncs.com/ps4qp8769mu96d0od24pwnahpjvli7nx71d9f33604-5166-4dbe-9b28-d82aa0ae7e70) 100% no-repeat;
    background-size: 100% 100%;
    width: 750rpx;
    display: flex;
    flex-direction: column;
  }

  .box_5 {
    width: 690rpx;
    height: 24rpx;
    flex-direction: row;
    display: flex;
    margin: 31rpx 0 0 30rpx;
  }

  .label_1 {
    width: 40rpx;
    height: 24rpx;
  }

  .label_2 {
    width: 38rpx;
    height: 24rpx;
    margin-left: 16rpx;
  }

  .image_1 {
    width: 110rpx;
    height: 24rpx;
    margin-left: 187rpx;
  }

  .image_2 {
    width: 60rpx;
    height: 20rpx;
    margin-left: 181rpx;
  }

  .block_2 {
    width: 43rpx;
    height: 20rpx;
    background: url(https://lanhu-dds-backend.oss-cn-beijing.aliyuncs.com/merge_image/imgs/cf32093e49204988a02804689d8b66ba_mergeImage.png) 100% no-repeat;
    background-size: 100% 100%;
    margin-left: 15rpx;
    display: flex;
    flex-direction: column;
  }

  .box_6 {
    width: 689rpx;
    height: 56rpx;
    flex-direction: row;
    display: flex;
    margin: 24rpx 0 9rpx 31rpx;
  }

  .image_3 {
    width: 20rpx;
    height: 35rpx;
    margin-top: 12rpx;
  }

  .text_1 {
    width: 146rpx;
    height: 34rpx;
    overflow-wrap: break-word;
    color: rgba(255, 255, 255, 1);
    font-size: 36rpx;
    font-family: Adobe Heiti Std R;
    text-align: left;
    white-space: nowrap;
    line-height: 24rpx;
    margin: 14rpx 0 0 251rpx;
  }

  .block_3 {
    border-radius: 28rpx;
    width: 170rpx;
    height: 56rpx;
    border: 2px solid rgba(255, 255, 255, 1);
    margin-left: 102rpx;
    flex-direction: row;
    display: flex;
  }

  .image_4 {
    width: 61rpx;
    height: 33rpx;
    margin: 13rpx 0 0 28rpx;
  }

  .group_1 {
    width: 33rpx;
    height: 33rpx;
    background: url(https://lanhu-dds-backend.oss-cn-beijing.aliyuncs.com/merge_image/imgs/d82b1e7e48634299a0c87742a0278f44_mergeImage.png) 100% no-repeat;
    background-size: 100% 100%;
    display: flex;
    flex-direction: column;
    margin: 14rpx 18rpx 0 30rpx;
  }

  .block_4 {
    background-color: rgba(242, 242, 242, 1.000000);
    width: 750rpx;
    height: 1375rpx;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
  }

  .box_3 {
    background-color: rgba(255, 255, 255, 1.000000);
    border-radius: 10rpx;
    width: 568rpx;
    height: 1120rpx;
    border: 2px solid rgba(196, 176, 129, 1);
    display: flex;
    flex-direction: column;
    /* margin: 83rpx 0 0 92rpx; */
    position: relative;
    /* top: -160rpx; */
    left: 92rpx;
  }

  .text-wrapper_1 {
    background-color: rgba(204, 204, 204, 1.000000);
    border-radius: 10rpx;
    height: 27rpx;
    display: flex;
    flex-direction: column;
    width: 52rpx;
    margin: 21rpx 0 0 501rpx;
    position: absolute;
  }

  .text_2 {
    width: 26rpx;
    height: 16rpx;
    overflow-wrap: break-word;
    color: rgba(254, 254, 254, 1);
    font-size: 18rpx;
    font-family: Adobe Heiti Std R;
    text-align: left;
    white-space: nowrap;
    line-height: 24rpx;
    margin: 5rpx 0 0 13rpx;
    position: absolute;
  }

  .text_3 {
    position: absolute;
    width: 444rpx;
    height: 68rpx;
    overflow-wrap: break-word;
    color: rgba(204, 204, 204, 1);
    font-size: 72rpx;
    font-family: Adobe Heiti Std R;
    text-align: left;
    line-height: 24rpx;
    margin: 228rpx 0 530rpx 72rpx;
  }

  .text-wrapper_2 {
    border-radius: 50%;
    height: 85rpx;
    border: 3px solid rgba(200, 165, 86, 1);
    display: flex;
    flex-direction: column;
    width: 85rpx;
    margin: 15rpx 0 53rpx 332rpx;
  }

  .text_4 {
    width: 43rpx;
    height: 44rpx;
    overflow-wrap: break-word;
    color: rgba(200, 165, 86, 1.000000);
    font-size: 72rpx;
    font-family: Adobe Heiti Std R;
    text-align: left;
    white-space: nowrap;
    line-height: 30rpx;
    /* margin: 18rpx 0 0 18rpx; */
    margin-top: 25%;
    margin-left: 25%;
  }

  .box_4 {
    background-image: linear-gradient(72deg, rgba(192, 171, 122, 1.000000) 0, rgba(192, 171, 122, 1.000000) 38.769531%, rgba(199, 180, 133, 1.000000) 100.000000%, rgba(199, 180, 133, 1.000000) 100.000000%);
    position: relative;
    width: 750rpx;
    height: 100rpx;
    margin-top: 33rpx;
    display: flex;
    flex-direction: row;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;

  }

  .group_2 {
    background-color: rgba(242, 242, 242, 1.000000);
    border-radius: 1rpx;
    width: 2rpx;
    height: 70rpx;
    display: flex;
    flex-direction: column;
    margin: 17rpx 0 0 374rpx;
  }

  .text_5 {
    position: absolute;
    left: 172rpx;
    top: 35rpx;
    width: 447rpx;
    height: 34rpx;
    overflow-wrap: break-word;
    color: rgba(255, 255, 255, 1);
    font-size: 36rpx;
    font-family: SimHei;
    text-align: center;
    white-space: nowrap;
    line-height: 36rpx;
  }
</style>
